﻿<prism:VisualStateAwarePage
    x:Name="pageRoot"
    x:Class="WinRT.SIP.UI.Views.CallPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinRT.SIP.UI.Views"
    xmlns:common="using:WinRT.SIP.UI.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:prism="using:Microsoft.Practices.Prism.StoreApps"
    mc:Ignorable="d"
    prism:ViewModelLocator.AutoWireViewModel="True">

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton"
                    AutomationProperties.AutomationId="CallPageGoBackButton"
                    Command="{Binding GoBackCommand}"
                    Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>

        <StackPanel HorizontalAlignment="Left" Width="400" Grid.Row="1" Margin="120,30,0,0">
            <TextBlock Margin="0,0,0,12" Text="{Binding CallStatus}" Style="{StaticResource SubheaderTextStyle}" />
            <TextBlock Margin="0,0,0,9" HorizontalAlignment="Stretch" TextAlignment="Center" Text="{Binding DisplayName}" Style="{StaticResource HeaderTextStyle}" />

            <Image Source="ms-appx:///Assets/DefaultProfile.png" Height="520" Visibility="{Binding StreamVideo, Converter={StaticResource NegatedBoolToVisibilityConverter}}" />
            <MediaElement Source="ms-media-stream-id:MediaStreamer-123" Height="520" Visibility="{Binding StreamVideo, Converter={StaticResource BooleanToVisibilityConverter}}" />

            <Grid Margin="0,-45,0,0" Visibility="{Binding IncomingCall, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Button Content="Answer" HorizontalAlignment="Stretch" Command="{Binding AnswerCallCommand}" />
                <Button Grid.Column="1" Content="Ignore" HorizontalAlignment="Stretch" Command="{Binding IgnoreCallCommand}" />
            </Grid>
            
            <Grid Margin="0,-145,0,0" Visibility="{Binding IncomingCall, Converter={StaticResource NegatedBoolToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <CaptureElement Grid.ColumnSpan="2" Name="capturePreview" Margin="3,0,0,0" Height="100" HorizontalAlignment="Left" />

                <ToggleButton Grid.Row="1" Content="Mute" HorizontalAlignment="Stretch" IsChecked="{Binding MuteOn, Mode=TwoWay}"/>
                <Button Grid.Row="1" Grid.Column="1" Content="End" HorizontalAlignment="Stretch" Command="{Binding EndCallCommand}" />
                <ToggleButton Grid.Row="1" Grid.Column="2" Content="Video" HorizontalAlignment="Stretch" IsChecked="{Binding VideoOn, Mode=TwoWay}" />
            </Grid>
        </StackPanel>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</prism:VisualStateAwarePage>
